package com.meng.menggaga.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meng.menggaga.R;
import com.meng.menggaga.entity.CommunityInfos.CommunityInfo;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 首页社区列表（两排）
 * 
 * @author simba
 * 
 */
public class CommunityListAdapter extends MengBaseAdapter<CommunityInfo> {

    public CommunityListAdapter(Context context, List<CommunityInfo> list, int pageSize, int res,
            int loadingRes, int retryRes) {
        super(context, list, pageSize, res, loadingRes, retryRes);
    }

    @Override
    protected View getView(int position, View convertView, ViewGroup parent, CommunityInfo value) {
        ViewHolder holder = (ViewHolder) convertView.getTag();

        if (holder == null) {
            holder = new ViewHolder();
            holder.leftViewHolder = new ItemViewHolder();
            holder.rightViewHolder = new ItemViewHolder();
            holder.leftViewHolder.icon =
                    (ImageView) (convertView.findViewById(R.id.left).findViewById(R.id.icon));
            holder.leftViewHolder.title =
                    (TextView) (convertView.findViewById(R.id.left).findViewById(R.id.title));
            holder.rightViewHolder.icon =
                    (ImageView) (convertView.findViewById(R.id.right).findViewById(R.id.icon));
            holder.rightViewHolder.title =
                    (TextView) (convertView.findViewById(R.id.right).findViewById(R.id.title));
            convertView.setTag(holder);
        }

        ImageLoader.getInstance().displayImage(value.cover_url, holder.leftViewHolder.icon);
        holder.leftViewHolder.title.setText(value.subject);

        ImageLoader.getInstance().displayImage(value.cover_url, holder.rightViewHolder.icon);
        holder.rightViewHolder.title.setText(value.subject);

        return convertView;
    }

    class ViewHolder {
        ItemViewHolder leftViewHolder;
        ItemViewHolder rightViewHolder;
    }

    class ItemViewHolder {
        ImageView icon;
        TextView title;
    }

    @Override
    public void nextPage(int start, int size, ILoadNextPageData<CommunityInfo> iLoadNextPageData) {
        super.nextPage(start, size, iLoadNextPageData);
        iLoadNextPageData.loadNextPageData(null);
    }

    @Override
    public int getRowColumn() {
        return 2;
    }

}
